package com.example.lvsuo.controller.cxg;


import com.example.lvsuo.entity.cxg.AdmContacts;
import com.example.lvsuo.modal.Result;
import com.example.lvsuo.service.cxg.IAdmContactsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 *
 *  admContacts Controller
 *
 *
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 心心念念
 * @since 2021-03-30
 */
@RestController
@RequestMapping("/admContacts")
public class AdmContactsController {

    @Autowired
    IAdmContactsService iAdmContactsService;


    /**
     * 查询 高查
     * @param selPlusData
     * @return
     */
    @GetMapping
    public Result queryAdmContacts(String selPlusData){
        List<AdmContacts> admContacts = iAdmContactsService.queryAdmContacts(selPlusData);
        return Result.back("ok","20000",admContacts);
    }

    /**
     * 按id查询
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result queryAdmContactsById(@PathVariable String id){
//        QueryWrapper queryWrapper = new QueryWrapper();//条件构造器
//        queryWrapper.eq("id",id);
        AdmContacts byId = iAdmContactsService.getById(id);
        return Result.back("ok","20000",byId);
    }

    /**
     * 添加 API
     * @param admContacts
     * @return
     */
    @PostMapping
    public Result addAdmContacts(@RequestBody AdmContacts admContacts){

//        System.out.println("admContacts==>"+admContacts);
         iAdmContactsService.save(admContacts);

        return Result.back("ok","20000");
    }

    /**
     * 修改 API
     * @param admContacts
     * @return
     */
    @PutMapping
    public Result updateAdmContacts(@RequestBody AdmContacts admContacts){

//        System.out.println("admContacts==>"+admContacts);
        iAdmContactsService.updateById(admContacts);

        return Result.back("ok","20000");
    }

    @DeleteMapping("/{id}")
    public Result delAdmContacts(@PathVariable String id){
        iAdmContactsService.removeById(id);
        return Result.back("ok","20000");
    }


}

